//
//  DSCallViewController.m
//  DS爱信
//
//  Created by 秦建英 on 14-6-4.
//  Copyright (c) 2014年 秦建英. All rights reserved.
//

#import "DSCallViewController.h"
#import "DingSh.h"
#import "CallHisViewController.h"
@interface DSCallViewController ()

@end

@implementation DSCallViewController
{
    UILabel *_label1;
    UILabel *_label;
    NSMutableArray *_tellArray;
    NSDate* _dat;
    NSString *_date;
    NSMutableArray *_listItems;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title =@"联系人详情";
    UIBarButtonItem *bbi =[[UIBarButtonItem alloc]initWithTitle:@"<<返回" style:UIBarButtonItemStyleDone target:self action:@selector(bbiClick)];
    self.navigationItem.leftBarButtonItem =bbi;
    self.view.backgroundColor =[UIColor whiteColor];
    [self infon];
    
    NSUserDefaults *myUserDefaults = [NSUserDefaults standardUserDefaults];
    if([myUserDefaults objectForKey:@"tellDemol"])
    {
        // 如果有直接拿出来继续存(从UserDefaults中取出的任何对象都是不可变的)
        _tellArray = [[NSMutableArray alloc] initWithArray:[myUserDefaults objectForKey:@"tellDemol"]];
        NSMutableDictionary *dict =[[NSMutableDictionary alloc]init];
        [dict setObject:_label1.text forKey:@"Demol"];
        [dict setObject: _label.text forKey:@"Demolname"];
        [_tellArray addObject:dict];
        [myUserDefaults setObject:_tellArray forKey:@"tellDemol"];
    }
    else
    {
        // 1.如果没有则创建一个新的用户数组
        _tellArray= [[NSMutableArray alloc] initWithCapacity:60];
        NSMutableDictionary *dict =[[NSMutableDictionary alloc]init];
        [dict setObject:_label1.text forKey:@"Demol"];
        [dict setObject:_label.text forKey:@"Demolname"];
        [_tellArray addObject:dict];
        [myUserDefaults setObject:_tellArray forKey:@"tellDemol"];
    }
    [myUserDefaults synchronize];
}
-(void)bbiClick
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
-(void)infon
{
    _listItems = (NSMutableArray *)[_array componentsSeparatedByString:@"   "];
    _label =[[UILabel alloc]initWithFrame:CGRectMake(135, 110, 180, 40)];
    [_listItems removeObjectAtIndex:0];
    _label.text =[NSString stringWithFormat:@"%@",[_listItems objectAtIndex:0]];
    _label.font =[UIFont fontWithName:@"Arial Rounded MT Bold" size:20];
    _label.layer.cornerRadius =10;
    [self.view addSubview:_label];
    self.view .backgroundColor =[UIColor whiteColor];
    _label1 =[[UILabel alloc]initWithFrame:CGRectMake(10, 200, 300, 40)];
    _label1.text =[NSString stringWithFormat:@"%@",[_listItems objectAtIndex:1]];
    _label1.font =[UIFont fontWithName:@"Arial Rounded MT Bold" size:20];
    _label1.layer.cornerRadius =10;
    _label1.textAlignment =NSTextAlignmentCenter;
    [self.view addSubview:_label1];
    UIImageView *image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"_about_tele@2x.png"]];
    image.frame =CGRectMake(30, 6, 30, 30);
    [_label1 addSubview:image];
    
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.tag =10;
    [btn setBackgroundImage:[UIImage imageNamed:@"ttttt_h.png"] forState:UIControlStateNormal];
    btn.frame =CGRectMake(10, 280, _label1.frame.size.width, 40);
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *imageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_calllog_call_normal.png"]];
    imageView.frame =CGRectMake(130, 6, 30, 30);
    [self.view addSubview:btn];
    [btn addSubview:imageView];
    
    UIImageView* image4=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"call_living_p@2x.jpg"]];
    image4.frame =CGRectMake(10,94 ,90, 90);
    [self.view addSubview:image4];
}
#pragma mark--dianhua
-(void)btnClick
{
    CallHisViewController *call =[[CallHisViewController alloc]init];
    [_listItems exchangeObjectAtIndex:0 withObjectAtIndex:1];
    call.tellName =_listItems;
    [self.navigationController pushViewController:call animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.view removeFromSuperview];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
@end
